package com.ymatou.iapi.godmch.testcase;

import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

import org.joda.time.DateTime;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.getAgentStatBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.getAgentStatCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
/**
*获取新增代理商数量统计
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getAgentStat{
	private static getAgentStatBean bean;
	private static getAgentStatCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取新增代理商数量统计");
	}

	@Before
	public void caseUp() {
		bean=new getAgentStatBean();
		call=new getAgentStatCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAgentStat_001() {
		Logger.start(true,"正例-获取新增代理商数量统计-纯渠道-新增1个代理");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			 usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			List<createmchBean> createListBean=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
			GodmchManageCallService.createmchCallForAgent(createListBean.toArray(new createmchBean[createListBean.size()]));
			
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Calendar c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, -1);
			String begin=sf.format(c.getTime());
			
			c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, 1);
			String end=sf.format(c.getTime());

			bean.setMchId(mchId);
			bean.setBegin(begin);
			bean.setEnd(end);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(),"验证code");
			Logger.verifyEquals("请求成功", call.getMessage(),"验证Message");
			Logger.verifyEquals(1, call.getNewTotal(),"验证newTotal");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAgentStat_002() {
		Logger.start(true,"正例-获取新增代理商数量统计-渠道+代理-新增1个代理");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			 usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean2);
			 usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
		    int mchId_agent2 = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			//创建邀请码
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(true);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);
			
			List<createmchBean> createListBean=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
			createListBean.get(0).setCountry("USA");
			GodmchManageCallService.createmchCallForAgent(createListBean.toArray(new createmchBean[createListBean.size()]));
			
			//创建邀请码
			CreateCodeBean codebean2=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean2.setIsPermanently(true);
			CreateCodeCall codeCall2=GodmchManageCallService.createCodeCall(codebean2);
			
			List<createmchBean> createListBean2=GodmchManageCallService.InitcreatemchBeanForAgent(mchId_agent, mchId_agent2);
			createListBean2.get(0).setCountry("USA");
			GodmchManageCallService.createmchCallForAgent(createListBean2.toArray(new createmchBean[createListBean2.size()]));
			
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Calendar c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, -1);
			String begin=sf.format(c.getTime());
			
			c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, 1);
			String end=sf.format(c.getTime());

			bean.setMchId(mchId_agent);
			bean.setBegin(begin);
			bean.setEnd(end);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(),"验证code");
			Logger.verifyEquals("请求成功", call.getMessage(),"验证Message");
			Logger.verifyEquals(1, call.getNewTotal(),"验证newTotal");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAgentStat_003() {
		Logger.start(true,"正例-获取新增代理商数量统计-vip渠道-新增1个代理");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			 usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			GodmchManageCallService.SetVip(mchId);
			
			List<createmchBean> createListBean=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
			GodmchManageCallService.createmchCallForAgent(createListBean.toArray(new createmchBean[createListBean.size()]));
			
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Calendar c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, -1);
			String begin=sf.format(c.getTime());
			
			c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, 1);
			String end=sf.format(c.getTime());

			bean.setMchId(mchId);
			bean.setBegin(begin);
			bean.setEnd(end);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(),"验证code");
			Logger.verifyEquals("请求成功", call.getMessage(),"验证Message");
			Logger.verifyEquals(1, call.getNewTotal(),"验证newTotal");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAgentStat_004() {
		Logger.start(true,"正例-获取新增代理商数量统计-纯渠道-新增2个代理");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			 usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean2);
			 usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent2 = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			List<createmchBean> createListBean=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
			GodmchManageCallService.createmchCallForAgent(createListBean.toArray(new createmchBean[createListBean.size()]));
			
			List<createmchBean> createListBean2=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent2);
			GodmchManageCallService.createmchCallForAgent(createListBean2.toArray(new createmchBean[createListBean2.size()]));
			
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Calendar c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, -1);
			String begin=sf.format(c.getTime());
			
			c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, 1);
			String end=sf.format(c.getTime());

			bean.setMchId(mchId);
			bean.setBegin(begin);
			bean.setEnd(end);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(),"验证code");
			Logger.verifyEquals("请求成功", call.getMessage(),"验证Message");
			Logger.verifyEquals(2, call.getNewTotal(),"验证newTotal");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAgentStat_005() {
		Logger.start(true,"正例-获取新增代理商数量统计-渠道+代理-新增2个代理");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			 usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean2);
			 usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
		    int mchId_agent2 = DGUserCallService.UserCreateCall(usercreateBean2);
		     usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
		    int mchId_agent3 = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			//创建邀请码
			CreateCodeBean codebean=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean.setIsPermanently(true);
			CreateCodeCall codeCall=GodmchManageCallService.createCodeCall(codebean);
			
			List<createmchBean> createListBean=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
			createListBean.get(0).setCountry("USA");
			GodmchManageCallService.createmchCallForAgent(createListBean.toArray(new createmchBean[createListBean.size()]));
			
			//创建邀请码
			CreateCodeBean codebean2=GodmchManageCallService.CreateAllMsgSellerMch();
			codebean2.setIsPermanently(true);
			CreateCodeCall codeCall2=GodmchManageCallService.createCodeCall(codebean2);
			
			List<createmchBean> createListBean2=GodmchManageCallService.InitcreatemchBeanForAgent(mchId_agent, mchId_agent2);
			createListBean2.get(0).setCountry("USA");
			GodmchManageCallService.createmchCallForAgent(createListBean2.toArray(new createmchBean[createListBean2.size()]));
			
			List<createmchBean> createListBean3=GodmchManageCallService.InitcreatemchBeanForAgent(mchId_agent, mchId_agent3);
			createListBean3.get(0).setCountry("USA");
			GodmchManageCallService.createmchCallForAgent(createListBean3.toArray(new createmchBean[createListBean3.size()]));
			
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Calendar c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, -1);
			String begin=sf.format(c.getTime());
			
			c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, 1);
			String end=sf.format(c.getTime());

			bean.setMchId(mchId_agent);
			bean.setBegin(begin);
			bean.setEnd(end);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(),"验证code");
			Logger.verifyEquals("请求成功", call.getMessage(),"验证Message");
			Logger.verifyEquals(2, call.getNewTotal(),"验证newTotal");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAgentStat_006() {
		Logger.start(true,"正例-获取新增代理商数量统计-vip渠道-新增2个代理");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			 usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean2);
			 usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent2 = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			GodmchManageCallService.SetVip(mchId);
			
			List<createmchBean> createListBean=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
			GodmchManageCallService.createmchCallForAgent(createListBean.toArray(new createmchBean[createListBean.size()]));
			
			List<createmchBean> createListBean2=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent2);
			GodmchManageCallService.createmchCallForAgent(createListBean2.toArray(new createmchBean[createListBean2.size()]));
			
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Calendar c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, -1);
			String begin=sf.format(c.getTime());
			
			c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, 1);
			String end=sf.format(c.getTime());

			bean.setMchId(mchId);
			bean.setBegin(begin);
			bean.setEnd(end);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(),"验证code");
			Logger.verifyEquals("请求成功", call.getMessage(),"验证Message");
			Logger.verifyEquals(2, call.getNewTotal(),"验证newTotal");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAgentStat_007() {
		Logger.start(true,"正例-获取新增代理商数量统计-新增0个代理");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
//			 usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
//			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
//			List<createmchBean> createListBean=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
//			GodmchManageCallService.createmchCallForAgent(createListBean.toArray(new createmchBean[createListBean.size()]));
			
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Calendar c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, -1);
			String begin=sf.format(c.getTime());
			
			c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, 1);
			String end=sf.format(c.getTime());

			bean.setMchId(mchId);
			bean.setBegin(begin);
			bean.setEnd(end);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(),"验证code");
			Logger.verifyEquals("请求成功", call.getMessage(),"验证Message");
			Logger.verifyEquals(0, call.getNewTotal(),"验证newTotal");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAgentStat_008() {
		Logger.start(true,"正例-获取新增代理商数量统计-mchId为空");
		try {
//			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
//			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
//			 usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
//			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean2);
//			//创建渠道
//			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
//			GodmchManageCallService.createmchCallForChannel(createBean1);
//			
//			List<createmchBean> createListBean=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
//			GodmchManageCallService.createmchCallForAgent(createListBean.toArray(new createmchBean[createListBean.size()]));
			
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Calendar c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, -1);
			String begin=sf.format(c.getTime());
			
			c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, 1);
			String end=sf.format(c.getTime());

			//bean.setMchId(mchId);
			bean.setBegin(begin);
			bean.setEnd(end);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatusCode1(),"验证code");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAgentStat_009() {
		Logger.start(true,"正例-获取新增代理商数量统计-begin为空");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			 usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			List<createmchBean> createListBean=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
			GodmchManageCallService.createmchCallForAgent(createListBean.toArray(new createmchBean[createListBean.size()]));
			
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Calendar c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, -1);
			String begin=sf.format(c.getTime());
			
			c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, 1);
			String end=sf.format(c.getTime());

			bean.setMchId(mchId);
		//	bean.setBegin(begin);
			bean.setEnd(end);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatusCode1(),"验证code");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAgentStat_010() {
		Logger.start(true,"正例-获取新增代理商数量统计-end为空");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			 usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			List<createmchBean> createListBean=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
			GodmchManageCallService.createmchCallForAgent(createListBean.toArray(new createmchBean[createListBean.size()]));
			
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Calendar c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, -1);
			String begin=sf.format(c.getTime());
			
			c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, 1);
			String end=sf.format(c.getTime());

			bean.setMchId(mchId);
			bean.setBegin(begin);
			//bean.setEnd(end);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("4001", call.getStatusCode1(),"验证code");					
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getAgentStat_011() {
		Logger.start(true,"正例-获取新增代理商数量统计-begin大于end");
		try {
			UserCreateBean usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId = DGUserCallService.UserCreateCall(usercreateBean2);
			 usercreateBean2 = DGUserCallService.initSellerUsercreateBean();
			int mchId_agent = DGUserCallService.UserCreateCall(usercreateBean2);
			//创建渠道
			createmchBean createBean1=GodmchManageCallService.InitcreatemchBeanForChannel(mchId);
			GodmchManageCallService.createmchCallForChannel(createBean1);
			
			List<createmchBean> createListBean=GodmchManageCallService.InitcreatemchBeanForAgent(mchId, mchId_agent);
			GodmchManageCallService.createmchCallForAgent(createListBean.toArray(new createmchBean[createListBean.size()]));
			
			SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			Calendar c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, -1);
			String begin=sf.format(c.getTime());
			
			c = Calendar.getInstance();
			c.add(Calendar.DAY_OF_MONTH, 1);
			String end=sf.format(c.getTime());

			bean.setMchId(mchId);
			bean.setBegin(end);
			bean.setEnd(begin);
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(),"验证code");
			Logger.verifyEquals("请求成功", call.getMessage(),"验证Message");
			Logger.verifyEquals(0, call.getNewTotal(),"验证newTotal");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}